#pragma once

#include "../common/StringHelper.hpp"
#include "../common/message.pb.h"
#include "../common/Log.hpp"
#include <google/protobuf/map.h>
#include <string>
#include <unordered_map>
#include <memory>

namespace micromq
{
    struct MsgQueue
    {
        using ptr = std::shared_ptr<MsgQueue>;

        MsgQueue()
        {}

        MsgQueue(const std::string& name, bool durable, bool exclusive, bool autoDelete, 
            const google::protobuf::Map<std::string, std::string>& args)
            : _name(name), _durable(durable), _exclusive(exclusive), _autoDelete(autoDelete), _args(args)
        {}

        std::string getArgs()
        {
            std::string result = "";
            for(auto it = _args.begin(); it != _args.end(); ++it)
            {
                result += it->first + "=" + it->second + "&";
            }
            if(result != "") result.pop_back();
            return result;
        }

        void setArgs(const std::string& args)
        {
            std::vector<std::string> result = StringHelper::split(args, "&");
            for(auto& str : result)
            {
                int pos = str.find("=");
                std::string key = str.substr(0, pos);
                std::string val = str.substr(pos+1); 
                _args[key] = val;
            }
        }

        ~MsgQueue()
        {}

        std::string _name;
        bool _durable;
        bool _exclusive; //是否为独占
        bool _autoDelete;
        google::protobuf::Map<std::string, std::string> _args;
    };
}